/// <reference path="jquery-1.4.1-vsdoc.js" />
$.fn.validator = function (config) {
    var obj = this;
    jQuery.each(obj, function (i, obj_sub) {
        var validateTipId = "ValidateTip_" + obj_sub.id;
        var validateMsgId = "ValidateMsg_" + obj_sub.id;
        var iset = $("#" + obj_sub.id).offset();
        if (!config.allowBlank) {
            $(obj_sub).after("<span id=\"" + validateTipId + "\" style=\"color:#FF0000\">*</span>");
        }
        $(obj_sub).after("<div id=\"" + validateMsgId + "\" style=\"padding:5px 0px 5px 5px;border: solid #FFD324 1px;background-color:#FFF9CF;\">" + config.tipmsg + "</div>");
        //$(obj_sub).after("<div id=\"" + validateMsgId + "\" style=\"padding:5px 0px 5px 5px;border: solid #DCE0E1 1px;background-color:#F5F5F5\">"+config.tipmsg+"</div>");

        //$("#" + validateMsgId).width($(obj_sub).width() -4 + "px");
        $("#" + validateMsgId).width($(obj_sub).width() < 140 ? 150 : $(obj_sub).width() - 4 + "px");

        $("#" + validateMsgId).css({ position: "absolute",
            display: "none",
            left: function () { return iset.left; },
            top: function () { return iset.top - $("#" + validateMsgId).outerHeight() + "px" },
            //clip:"rect(1px " + ($("#"+validateMsgId).width() + ($.browser.msie?6:8) + "px") + " " + ($("#"+validateMsgId).height() + ($.browser.msie?1:2) + "px") + " " + ($("#"+validateMsgId).width() - 15 + "px") + ")",
            "font-size": obj.css("font-size")
        });

        $(obj_sub).focus(function () {
            //$("#"+validateMsgId).show().css({top:function(){return iset.top-$(this).height()-13+"px"}});	
        }).blur(function () {
            $("#" + validateMsgId).hide();
            if (!config.reg.test($(obj_sub).val())) {
                //$(obj_sub).css("border","solid #FF0000 1px;");	
                $("#" + validateTipId).text("！").css("color", "red");
            }
            else {
                //$(obj_sub).css("border","");
                $("#" + validateTipId).text("√").css("color", "green");
            }

        }).mouseover(function () {
            var iset = $(this).offset();
            $("#" + validateMsgId).show().css({ top: function () { return (iset.top - $(this).height() - 13) < 0 ? iset.top + $(obj_sub).height() + 6 : iset.top - $(this).height() - 13 + "px" } });
        }).mouseout(function () {
            $("#" + validateMsgId).hide();
        })
    });
};


var validatorSettings = {
    entity_code: { reg: /\d/, tipmsg: '1、注册号为营业执照注册号<br/>2、新的营业执照号为15位数字<br/>3、执照号后面的(1-1)，为副本，不用录入', allowBlank: false },
    entity_name: { reg: /\d/, tipmsg: '企业名称', allowBlank: false },
    pro_code: { reg: /\d/, tipmsg: '<iframe frameborder="0 " style= "position:absolute;visibility: inherit;top:-1px;left:-1px;width:160;height:60;z-index:-1;filter:alpha(opacity=0); "></iframe>1、条形码为商品包装上条形码<br/>2、条形码全部由数字组成<br/>3、条形码录入不能为空', allowBlank: false },
    out_day: { reg: /\d/, tipmsg: '保质期', allowBlank: false },
    gov_code: { reg: /\d/, tipmsg: '1、请输入组织机构代码<br/>2、格式为15位数字', allowBlank: false },
    gov_name: { reg: /^[\u4e00-\u9fa5a-zA-Z]{0,}$/, tipmsg: '1、请输入组织机构代码<br/>2、格式为15位数字', allowBlank: false },
    _name: { reg: /^[\u4e00-\u9fa5a-zA-Z]{0,}$/, tipmsg: '负责人姓名', allowBlank: false },
    tel: { reg: /^((\d{3,4})(\-){0,1}(\d{7,8}))|((0)(\d{11}))$/, tipmsg: '电话号码', allowBlank: false },
    email: { reg: /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/, tipmsg: '电子邮箱', allowBlank: true },
    loginanme: { reg: /^[\u4e00-\u9fa5a-zA-Z]{0,}$/, tipmsg: '登录名', allowBlank: false },
    realname: { reg: /^[\u4e00-\u9fa5a-zA-Z]{0,}$/, tipmsg: '真实姓名', allowBlank: false },
    notnull: { reg: /^[\u4e00-\u9fa5a-zA-Z]{0,}$/, tipmsg: '', allowBlank: false },
    discount: { reg: /^\d+$/, tipmsg: '', allowBlank: false },
    to_entitycode: { reg: /\d/, tipmsg: '1、双击打开单位选择窗口<br/>2、输入部分注册号或单位名称首字母可以进行筛选', allowBlank: false },
    lawnumber: { reg: /^\d+$/, tipmsg: '工商执法号', allowBlank: false }
}